package com.woniuxy.juc.cas.util;

import sun.misc.Unsafe;

import java.lang.reflect.Field;

/**
 * <P> @Author: ideaAdmin
 * <P> TODO: Class
 * <P> TODO: 通过反射返回Unsafe对象
 * <P> Date: 2022/4/10:10:07
 * <P> Description:
 */

public class UnsafeAccessor {
    static Unsafe unsafe;

    static {
        try {
            Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");             theUnsafe.setAccessible(true);
            unsafe = (Unsafe) theUnsafe.get(null);
        } catch (NoSuchFieldException | IllegalAccessException e) {
            throw new Error(e);
        }
    }

    public static Unsafe getUnsafe() {
        return unsafe;
    }
}
